package com.skt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.skt.domain.PO.CartItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CartItemMapper extends BaseMapper<CartItem> {

    /**
     * 根据购物车ID查询有效购物车项
     */
    @Select("SELECT * FROM cart_item WHERE cart_id = #{cartId} AND status = 1")
    List<CartItem> selectByCartId(@Param("cartId") Long cartId);

    /**
     * 根据购物车ID和商品ID查询购物车项
     */
    @Select("SELECT * FROM cart_item WHERE cart_id = #{cartId} AND costume_id = #{costumeId} " +
            "AND deleted_at IS NULL LIMIT 1")
    CartItem selectByCartIdAndCostumeId(@Param("cartId") Long cartId,
                                        @Param("costumeId") Long costumeId);

    /**
     * 根据ShoppingCart购物车ID删除CartItem中对应的购物车
     * @param cartId
     */
    @Delete("DELETE FROM cart_item WHERE cart_id = #{cartId}")
    void deleteByCartId(Long cartId);
}
